import uniqueId from '@form-create/utils/lib/unique';
import {localeProps, makeOptionsRule, makeRequiredRule} from '../../utils/index';

const label = '单选框';
const name = 'jd-radio';

export default {
    icon: 'icon-radio',
    label,
    name,
    rule({t}) {
        const opt = t('props.option');
        return {
            type: 'radio',
            field: 'DXK',
            title: '单选框',
            info: '',
            effect: {
                fetch: '',
                defValue: ''
            },
            $required: false,
            validate: false,
            props: {
                
            },
            options: [1, 2].map(value => {
                return {
                    label: opt + value,
                    value,
                }
            })
        };
    },
    watch: {
        'type': function(val) {
            if (val.value == 'button'){
                val.api.rule[3].hidden = false;
            } else {
                val.api.rule[3].hidden = true;
            }
        },
        'useScript': function(val){
            if (val.value.isScript){
                val.rule.inject = true;
                val.rule.on = val.value._script;
            } else{
                val.rule.inject = false;
                val.rule.on = {};
            }
        },
    },
    props(_, {t}) {
        return localeProps(t, name + '.props', [
            makeRequiredRule(),
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'disabled', title: '是否禁用'} 
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch',field: 'type',title: '按钮形式',props: {activeValue: 'button', inactiveValue: 'default'}},
                ],
            },
            {
                type: 'row',
                props: {gutter: 5},
                hidden: true,
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'textColor', title: '文本颜色'}
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input',field: 'fill',title: '按钮背景'}
                        ]
                    }
                ]
            },
            makeOptionsRule(t, 'options'),
            {type: 'ItemScript', field: 'useScript', value: ''},
        ]);
    }
};